#include<bits/stdc++.h>
using namespace std;
map<string,int>net;
int n;
bool ERR(string str){
	str+='.';
	int tod=1,num=0;
	bool tf=true;
	for(int i=0;i<str.size();i++){
		if(str[i]=='-'){tf=false;break;}
		if(str[i]=='.'||str[i]==':'){
			if(tod<4&&str[i]==':'){tf=false;break;}
			if(tod==4&&str[i]=='.'){tf=false;break;}
			if(tod<=4){
				if(num>255){tf=false;break;}
			}
			else {
				if(num>65535){tf=false;break;}
			}
			num=0;
			tod++;
		}	
		else num=num*10+(str[i]-'0');	
	}
	return tf;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		string str1,str2;
		cin>>str1>>str2;
		if(!ERR(str2)){printf("ERR\n");continue;}
		
		if(str1[0]=='S'){
			if(!net[str2]){net[str2]=i;printf("OK\n");continue;}
			else {printf("FAIL\n");continue;}
		}
		else{
			if(net[str2]){printf("%d\n",net[str2]);continue;}
			else printf("FAIL\n");
		}
	}
	return 0;
}

